#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 5e5+10;

int n,m,cnt[N],rk[N],ork[N<<1],id[N],px[N],sa[N],stk[N],top,ht[N],l[N];
char s[N];
ll ans;

void getSA(){
	m = 300; for(int i = 1;i <= n;i++) ++cnt[rk[i] = s[i]];
	for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
	for(int i = n;i >= 1;i--) sa[cnt[rk[i]]--] = i;
	for(int h = 1,p;h <= n;h <<= 1,m = p){
		p = 0;for(int i = n;i > n-h;i--) id[++p] = i;
		for(int i = 1;i <= n;i++) if(sa[i] > h) id[++p] = sa[i] - h;
		for(int i = 1;i <= m;i++) cnt[i] = 0;
		for(int i = 1;i <= n;i++) ++cnt[px[i] = rk[id[i]]];
		for(int i = 1;i <= m;i++) cnt[i] += cnt[i-1];
		for(int i = n;i >= 1;i--) sa[cnt[px[i]]--] = id[i];
		for(int i = 1;i <= n;i++) ork[i] = rk[i];
		p = 0;
		for(int i = 1;i <= n;i++)
			rk[sa[i]] = (ork[sa[i-1]] == ork[sa[i]] && ork[sa[i-1]+h] == ork[sa[i]+h]) ? p : ++p;
	}
	for(int i = 1,p = 0;i <= n;i++){
		if(p) p--;
		while(s[i+p] == s[sa[rk[i]-1]+p]) p++;
		ht[rk[i]] = p;
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	scanf("%s",s+1); n = strlen(s+1); getSA();
	ans = 1ll * n * (n + 1) / 2 * (n-1);
	for(int i = 1;i <= n;i++){
		while(ht[i] < ht[stk[top]]) top--;
		l[i] = i - stk[top]; stk[++top] = i;
	}
	ht[n+1] = -1; stk[top=0] = n+1;
	for(int i = n;i >= 1;i--){
		while(ht[i] <= ht[stk[top]]) top--;
		ans -= 2ll * ht[i] * l[i] * (stk[top] - i); stk[++top] = i;
	}printf("%lld\n",ans);
	return 0;
}
